package com.biz.primus.ms.commodity.api;

import com.biz.primus.base.vo.IdNameVo;
import com.biz.primus.commodity.vo.BrandQueryVo;
import com.biz.primus.commodity.vo.SyncBrandVo;
import com.biz.primus.commodity.vo.backend.BrandListItemVo;
import com.biz.primus.commodity.vo.backend.CreateBrandVo;
import com.biz.primus.commodity.vo.backend.UpdateBrandVo;
import com.biz.primus.common.vo.SpringPageVO;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.commodity.dao.redis.BrandRedisDao;
import com.biz.primus.ms.commodity.dao.repository.brand.BrandRepository;
import com.biz.primus.ms.commodity.service.backend.BrandService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yanweijin
 * @date 2017/9/12
 */
@RestController
@RequestMapping("soa/brandService")
public class BrandApiController extends BaseApiController {

    private final BrandRepository brandRepository;

    private final BrandRedisDao brandRedisDao;

    private final BrandService brandService;

    public BrandApiController(BrandRepository brandRepository, BrandRedisDao brandRedisDao, BrandService brandService) {
        this.brandRepository = brandRepository;
        this.brandRedisDao = brandRedisDao;
        this.brandService = brandService;
    }

    @ApiOperation("获取品牌列表")
    @PostMapping("findAll")
    SpringPageVO<BrandListItemVo> listBrand(@RequestBody BrandQueryVo brandQueryVo) {
        return brandService.listBrands(brandQueryVo);
    }

    @ApiOperation("创建品牌")
    @PostMapping("createBrand")
    CreateBrandVo createBrand(@RequestBody CreateBrandVo createbrandVo) {
        return brandService.createBrand(createbrandVo);
    }

    @ApiOperation("编辑品牌")
    @PostMapping("updateBrand")
    void updateBrand(@RequestBody UpdateBrandVo updateCategoryVo) {
        brandService.updateBrand(updateCategoryVo);
    }

    @ApiOperation("获取 品牌 编辑信息")
    @GetMapping("getBrandById")
    UpdateBrandVo getBrandById(@RequestParam("id") Long brandId) {
        return brandService.getUpdateBrandVo(brandId);
    }


    @ApiOperation("前台通过分类获取App端展示的品牌信息")
    @GetMapping("frontend/listBrandByCategoryId")
    List<IdNameVo> listBrandByCategoryId(@RequestParam(value = "categoryId",required = false) Long categoryId) {
        return brandService.listBrandByCategoryId(categoryId);
    }

    @ApiOperation("erp同步品牌信息")
    @PostMapping("syncBrands")
    void syncBrands(@RequestBody List<SyncBrandVo> syncBrandVos){
        brandService.syncBrands(syncBrandVos);
    }

}
